package com.ruoyi.mall.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.mall.domain.OrderLogistics;
import com.ruoyi.mall.enums.OrderLogisticsEnum;
import com.ruoyi.mall.service.OrderLogisticsService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单物流
 *
 * @author www.joolun.com
 * @date 2019-09-16 09:53:17
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/orderlogistics")
public class OrderLogisticsController extends BaseController {

    private final OrderLogisticsService orderLogisticsService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param orderLogistics 订单物流
    * @return
    */
    @GetMapping("/page")
    @SaCheckPermission("@ato.hasAuthority('mall:orderlogistics:index")
    public R<Object> getOrderLogisticsPage(Page<OrderLogistics> page, OrderLogistics orderLogistics) {
        return R.ok(orderLogisticsService.page(page,Wrappers.query(orderLogistics)));
    }

    /**
    * 通过id查询订单物流
    * @param id
    * @return R
    */
    @GetMapping("/{id}")
    @SaCheckPermission("@ato.hasAuthority('mall:orderlogistics:get")
    public R<OrderLogistics> getById(@PathVariable("id") String id){
        return R.ok(orderLogisticsService.getById(id));
    }

    /**
    * 新增订单物流
    * @param orderLogistics 订单物流
    * @return R
    */
    @PostMapping
    @SaCheckPermission("@ato.hasAuthority('mall:orderlogistics:add")
    public R<Void> save(@RequestBody OrderLogistics orderLogistics){
        return toAjax(orderLogisticsService.save(orderLogistics));
    }

    /**
    * 修改订单物流
    * @param orderLogistics 订单物流
    * @return R
    */
    @PutMapping
    @SaCheckPermission("@ato.hasAuthority('mall:orderlogistics:edit")
    public R<Void> updateById(@RequestBody OrderLogistics orderLogistics){
        return toAjax(orderLogisticsService.updateById(orderLogistics));
    }

    /**
    * 通过id删除订单物流
    * @param id
    * @return R
    */
    @DeleteMapping("/{id}")
    @SaCheckPermission("@ato.hasAuthority('mall:orderlogistics:del")
    public R<Void> removeById(@PathVariable String id){
        return toAjax(orderLogisticsService.removeById(id));
    }

	/**
	 * 获取相关枚举数据的字典
	 * @param type
	 * @return
	 */
	@GetMapping("/dict/{type}")
	public R<List<Map<String,String>>> getDictByType(@PathVariable String type) {
		return R.ok(OrderLogisticsEnum.queryAll(type));
	}
}
